﻿using System.Data;
using System.Net;
namespace PssFramework
{
    public class Config
    {
        private static Config instance;

       
        private string hostIp;

        public string HostIp
        {
            get { return hostIp; }
            set { hostIp = value; }
        }
        private string ip;
        public string Ip
        {
            get { return ip; }
            set { ip = value; }
        }
        private int publishPort;

        public int PublishPort
        {
            get { return publishPort; }
            set { publishPort = value; }
        }
        private int subscribePort;

        public int SubscribePort
        {
            get { return subscribePort; }
            set { subscribePort = value; }
        }

        private Config()
        {
            DataSet ds=Utils.getConfig();
            ip = ds.Tables[0].Rows[0]["IP"].ToString();
            publishPort = int.Parse(ds.Tables[0].Rows[0]["PublishPort"].ToString());
            subscribePort = int.Parse(ds.Tables[0].Rows[0]["SubscribePort"].ToString());

            IPAddress[] ipadds = Dns.GetHostAddresses(Dns.GetHostName());
            foreach (IPAddress ad in ipadds)
            {
                if (ad.GetAddressBytes().Length == 4)
                {
                    hostIp = ad.ToString();
                }
            }
        }
        public static Config getInstance()
        {
             if (instance == null)
            {
                 instance=new Config();
            }
            return instance; 
        }
    }
}
